﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using MDV.GUI;
using MDV.Frameworks;



namespace MDV.GUI
{
    public partial class FormSetting : DevExpress.XtraEditors.XtraForm
    {
        #region variables
        Common com = new Common();
        string test = String.Empty;
        public static int fontSize=10 ;
        public static string fontFamily = "Arial";
        public static int fontSizeChange =0;
        public static int fontFamilyChange =0;
        public static int TextFont;
        int temp = frmMain.applyCheck;
        string version = String.Empty;
        #endregion
        public FormSetting()
        {
            InitializeComponent();
        }


        private void btClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void XtraForm1_Load(object sender, EventArgs e)
        {
            lblAbout.Text = com.strAboutUs;
            lblUpdate.Text = "Medical Dictionary Virtualization"
                             + "\nVersion " + version
                             + "\n(C) Unicorn Team"
                             + "\n\nIf having new version, we will provide a update file for you."
                             + "\nYou can download it and click [Open File] button at the tab to read it";

            for (int i = 10; i < 70; i+=5)
                cbFontSize.Items.Add(i.ToString());
            if(temp==0)
            cbFontSize.SelectedIndex = 0;
            //-----------Tạo danh sách font chữ
            System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
            foreach (FontFamily family in fonts.Families)
            {
                cbTextFont.Items.Add(family.Name.ToString());
            }
            if(temp==0)
            cbTextFont.SelectedIndex = 8;
            if (temp != 0)
            {

                fontSizeChange = frmMain.returnfontSize;
                fontFamilyChange = frmMain.returnTextFont;
                cbTextFont.SelectedIndex = fontFamilyChange;
                cbFontSize.SelectedIndex = fontSizeChange;
            }
        }

        private void btUpdate_Click(object sender, EventArgs e)
        {
            DialogResult dr = new DialogResult();
            OpenFileDialog dialogUpdate = new OpenFileDialog();
            dialogUpdate.Filter = "Text Files (*.txt)|*.txt|Word Documents" +
                                     "(*.doc)|*.doc|All Files (*.*)|*.*";
            dialogUpdate.ShowReadOnly = true;
            dialogUpdate.Multiselect = true;
            dialogUpdate.Title = "Open files for custom application";
           
            
            if ( dialogUpdate.ShowDialog() == DialogResult.OK)
            {
                if (MessageBox.Show("Are you sure to update?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    //lblCheck.Text = Path.GetFileName(dialogUpdate.FileName);
                    Business.Update update = new Business.Update();
                    //lblUpdate.Text = update.ReadFile(dialogUpdate.FileName); //show ra query
                    update.UpdateOnDB(dialogUpdate.FileName);
                    lblCheckUpdate.Text = update.check;
                }
                else
                {
                    lblCheckUpdate.Text = "Update Fail. You can retry. Make sure that file is correct.";
                }
            }
            else 
            {
                //lblCheckUpdate.Text = "Stopped";
                
            }
            dialogUpdate.Dispose();
        }

        private void btApply_Click(object sender, EventArgs e)
        {
            temp++;
            fontSize = int.Parse(cbFontSize.SelectedItem.ToString());
            fontFamily = cbTextFont.SelectedItem.ToString();
            frmMain.returnfontSize = cbFontSize.SelectedIndex;
            frmMain.returnTextFont = cbTextFont.SelectedIndex;
            frmMain.applyCheck += 1;
          
            this.Close();
        }

        private void bntDefault_Click(object sender, EventArgs e)
        {
            temp = 0;
            cbFontSize.SelectedIndex = 0;
            cbTextFont.SelectedIndex = 8;
       
        }



      
    
    }
}